//
//  ContactInfoVController.m
//  Tiger
//
//  Created by Wangli on 12-5-31.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ContactInfoVController.h"
#import <QuartzCore/QuartzCore.h>
@interface ContactInfoVController ()

@end

@implementation ContactInfoVController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"screen_bg.png"]]];
    
    UIImageView* tTopImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"more_top.png"]];
    tTopImgView.frame =CGRectMake(0, 0, 320, 28);
    UILabel* tWordLabel = [[UILabel alloc] initWithFrame:CGRectMake(126, 1, 68, 21)];
    [tWordLabel setFont:[UIFont boldSystemFontOfSize:17.f]];
    [tWordLabel setBackgroundColor:[UIColor clearColor]];
    [tWordLabel setText:@"联系信息"];
    [tWordLabel setTextColor:[UIColor whiteColor]];
    [tTopImgView addSubview:tWordLabel];
    [tWordLabel release];
    [self.view addSubview:tTopImgView];
    [tTopImgView release];
    
    UIButton* tClearResBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    tClearResBtt.frame =CGRectMake(0, 0, 320, 390);
    [tClearResBtt addTarget:self action:@selector(clearKeyBorad) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:tClearResBtt];
    
    UILabel* tLeftLabelPeo = [[UILabel alloc] initWithFrame:CGRectMake(20, 38, 100, 26)];
    [tLeftLabelPeo setBackgroundColor:[UIColor clearColor]];
    [tLeftLabelPeo setTextColor:[UIColor whiteColor]];
    [tLeftLabelPeo setText:@"订货人："];
    [tLeftLabelPeo setFont:[UIFont boldSystemFontOfSize:17.f]];
    tLeftLabelPeo.textAlignment =UITextAlignmentRight;
    [self.view addSubview:tLeftLabelPeo];
    [tLeftLabelPeo release];
    UITextField* tPeoField = [[UITextField alloc] initWithFrame:CGRectMake(120, 42, 160, 30)];
    tPeoField.tag = 0x200;
    tPeoField.clipsToBounds =NO;
    CALayer* tLayer = [CALayer layer];
    tLayer.frame =CGRectMake(0, -4, 160, 30);
    tLayer.cornerRadius =4.f;
    [tLayer setBackgroundColor:[UIColor whiteColor].CGColor];
    [tPeoField.layer addSublayer:tLayer];
    [self.view addSubview:tPeoField];
    [tPeoField release];
    
    
    UILabel* tLeftLabelPhone = [[UILabel alloc] initWithFrame:CGRectMake(20, 78, 100, 26)];
    [tLeftLabelPhone setBackgroundColor:[UIColor clearColor]];
    [tLeftLabelPhone setTextColor:[UIColor whiteColor]];
    [tLeftLabelPhone setText:@"联系电话："];
    [tLeftLabelPhone setFont:[UIFont boldSystemFontOfSize:17.f]];
    tLeftLabelPhone.textAlignment =UITextAlignmentRight;
    [self.view addSubview:tLeftLabelPhone];
    [tLeftLabelPhone release];
    UITextField* tPhoneField = [[UITextField alloc] initWithFrame:CGRectMake(120, 82, 160, 30)];
    tPhoneField.tag = 0x201;
    tPhoneField.clipsToBounds =NO;
    CALayer* tPhLayer = [CALayer layer];
    tPhLayer.frame =CGRectMake(0, -4, 160, 30);
    tPhLayer.cornerRadius =4.f;
    [tPhLayer setBackgroundColor:[UIColor whiteColor].CGColor];
    [tPhoneField.layer addSublayer:tPhLayer];
    [self.view addSubview:tPhoneField];
    [tPhoneField release];
    

    UIBarButtonItem* tConfBt = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(requestInfo)];
    //[tConfBt setTintColor:[UIColor blackColor]];
    self.navigationItem.rightBarButtonItem =tConfBt;
    [tConfBt release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

-(void) clearKeyBorad{
    UITextField* tPeoField =(UITextField*)[self.view viewWithTag:0x200];
    [tPeoField resignFirstResponder];
    
    UITextField* tPhoField =(UITextField*)[self.view viewWithTag:0x201];
    [tPhoField resignFirstResponder];
}

-(void) requestInfo{
    UITextField* tPeoField =(UITextField*)[self.view viewWithTag:0x200];
    UITextField* tPhoField =(UITextField*)[self.view viewWithTag:0x201];
    UIAlertView* tAlertView =[[UIAlertView alloc] initWithTitle:@"提示" message:@"联系人和电话不可为空！" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles: nil];
    if ([tPeoField.text length] <= 0) {
        [tAlertView show];
        [tAlertView release];
        return;
    }
    if ([tPhoField.text length] <= 0) {
        [tAlertView show];
        [tAlertView release];
        return;
    }
    [tAlertView release];
    
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
	[request setDelegate:self];
	[request startAsynchronous];
}


#pragma mark ASIHTTPRequestDelegate methods
- (void)requestStarted:(ASIHTTPRequest *)request
{
	[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    UIAlertView* tAlertView =[[UIAlertView alloc] initWithTitle:@"提示" message:@"提交订单成功！" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles: nil];
    [tAlertView show];
    [tAlertView release];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    UIAlertView* tAlertView =[[UIAlertView alloc] initWithTitle:@"提示" message:@"提交订单失败请稍后再试！" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles: nil];
    [tAlertView show];
    [tAlertView release];
}
@end
